package com.bupt.jack;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends Activity {

	private GridView homeOptions;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
        homeOptions = (GridView) findViewById(R.id.homeOptions);
        
        MyImageAdapter myImageAdapter = new MyImageAdapter(this);
        
        homeOptions.setAdapter(myImageAdapter);
        
    }

    private class MyImageAdapter extends BaseAdapter{

    	private Context myContext;
    	
    	private Integer[] mImageIds = {
    			R.drawable.option1 , R.drawable.option2 , R.drawable.option3,
    			R.drawable.option4 , R.drawable.option5 , R.drawable.option6,
    			R.drawable.option7 , R.drawable.option8 , R.drawable.option9,
    			R.drawable.option9 , R.drawable.option9 , R.drawable.option9
    			
    	};
    	
    	public MyImageAdapter(Context context){
    		this.myContext = context;
    	}
    	
		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return mImageIds.length;
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return mImageIds[position];
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			
			ImageView imageView = new ImageView(myContext);
			
			imageView.setImageResource(this.mImageIds[position]);
			
			imageView.setAdjustViewBounds(true);
			
			imageView.setBackgroundResource(android.R.drawable.picture_frame);
			
			return imageView;
		}
    	
    }
    
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}
